<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>GrPPI: reduce_pattern.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { init_search(); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="logo.svg"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">GrPPI
   &#160;<span id="projectnumber">0.3.1</span>
   </div>
   <div id="projectbrief">Generic and Reusable Parallel Pattern Interface</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_0966d06610f72609fd9aa4979c2b5a92.html">common</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">reduce_pattern.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="reduce__pattern_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;</div><div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="preprocessor">#ifndef GRPPI_COMMON_REDUCE_PATTERN_H</span></div><div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="preprocessor">#define GRPPI_COMMON_REDUCE_PATTERN_H</span></div><div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;</div><div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;</div><div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespacegrppi.html">grppi</a>{</div><div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;</div><div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> Combiner, <span class="keyword">typename</span> Identity&gt;</div><div class="line"><a name="l00034"></a><span class="lineno"><a class="line" href="classgrppi_1_1reduce__t.html">   34</a></span>&#160;<span class="keyword">class </span><a class="code" href="classgrppi_1_1reduce__t.html">reduce_t</a> {</div><div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;<span class="keyword">public</span>:</div><div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;</div><div class="line"><a name="l00044"></a><span class="lineno"><a class="line" href="classgrppi_1_1reduce__t.html#ab2eaf12acd4842c4b4399fd759b462ed">   44</a></span>&#160;  <a class="code" href="classgrppi_1_1reduce__t.html#ab2eaf12acd4842c4b4399fd759b462ed">reduce_t</a>(<span class="keywordtype">int</span> wsize, <span class="keywordtype">int</span> <a class="code" href="classgrppi_1_1reduce__t.html#add1893b889d024147efaba42422cedd1">offset</a>, Identity <span class="keywordtype">id</span>, Combiner &amp;&amp; combine_op) :</div><div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;    window_size_{wsize}, offset_{<a class="code" href="classgrppi_1_1reduce__t.html#add1893b889d024147efaba42422cedd1">offset</a>}, </div><div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;    identity_{<span class="keywordtype">id</span>}, combiner_{combine_op}</div><div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;  {}</div><div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;</div><div class="line"><a name="l00055"></a><span class="lineno"><a class="line" href="classgrppi_1_1reduce__t.html#a7319e39544c636e08643bc7f572def58">   55</a></span>&#160;  <span class="keywordtype">void</span> <a class="code" href="classgrppi_1_1reduce__t.html#a7319e39544c636e08643bc7f572def58">add_item</a>(Identity &amp;&amp; item) {</div><div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;    <span class="keywordflow">if</span> (remaining&gt;0) {</div><div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;      remaining--;</div><div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;    }</div><div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;    <span class="keywordflow">else</span> {</div><div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;      items.push_back(std::forward&lt;Identity&gt;(item));</div><div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;    }</div><div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;  }</div><div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;</div><div class="line"><a name="l00067"></a><span class="lineno"><a class="line" href="classgrppi_1_1reduce__t.html#a1c79c7ee533b17d782881b2374216b9b">   67</a></span>&#160;  <span class="keywordtype">bool</span> <a class="code" href="classgrppi_1_1reduce__t.html#a1c79c7ee533b17d782881b2374216b9b">reduction_needed</a>()<span class="keyword"> const </span>{</div><div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;    <span class="keywordflow">return</span> !items.empty() &amp;&amp; (items.size() &gt;= window_size_);</div><div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;  }</div><div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;</div><div class="line"><a name="l00075"></a><span class="lineno"><a class="line" href="classgrppi_1_1reduce__t.html#a7a7b53d2b18502ddb41792a696dfdf3e">   75</a></span>&#160;  Combiner <a class="code" href="classgrppi_1_1reduce__t.html#a7a7b53d2b18502ddb41792a696dfdf3e">combiner</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> combiner_; }</div><div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;</div><div class="line"><a name="l00081"></a><span class="lineno"><a class="line" href="classgrppi_1_1reduce__t.html#a4966590f756cce91306ae117c6cb4d02">   81</a></span>&#160;  <span class="keywordtype">int</span> <a class="code" href="classgrppi_1_1reduce__t.html#a4966590f756cce91306ae117c6cb4d02">window_size</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> window_size_; }</div><div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;</div><div class="line"><a name="l00087"></a><span class="lineno"><a class="line" href="classgrppi_1_1reduce__t.html#add1893b889d024147efaba42422cedd1">   87</a></span>&#160;  <span class="keywordtype">int</span> <a class="code" href="classgrppi_1_1reduce__t.html#add1893b889d024147efaba42422cedd1">offset</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> offset_; }</div><div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;</div><div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;  <span class="keyword">template</span> &lt;<span class="keyword">typename</span> E&gt;</div><div class="line"><a name="l00094"></a><span class="lineno"><a class="line" href="classgrppi_1_1reduce__t.html#a14fd59017bf9aae3e37eabd38c75f849">   94</a></span>&#160;  <span class="keyword">auto</span> <a class="code" href="classgrppi_1_1reduce__t.html#a14fd59017bf9aae3e37eabd38c75f849">reduce_window</a>(<span class="keyword">const</span> E &amp; e) {</div><div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;    <span class="keyword">auto</span> red = e.reduce(items.begin(), items.size(), identity_, combiner_);</div><div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;    <span class="keywordflow">if</span> (offset_ &gt; window_size_) {</div><div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;      remaining = offset_ - window_size_;</div><div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;      items.clear();</div><div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;    }</div><div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;    <span class="keywordflow">else</span> {</div><div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;      items.erase(items.begin(), std::next(items.begin(), offset_));</div><div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;    }</div><div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;    <span class="keywordflow">return</span> red;</div><div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;  }</div><div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;  </div><div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;  <span class="keyword">template</span>&lt;<span class="keyword">typename</span> T&gt;</div><div class="line"><a name="l00107"></a><span class="lineno"><a class="line" href="classgrppi_1_1reduce__t.html#a2629935ab39526c99432353e68172f62">  107</a></span>&#160;  <span class="keyword">auto</span> <a class="code" href="classgrppi_1_1reduce__t.html#a2629935ab39526c99432353e68172f62">operator()</a>(T &amp;&amp;item){</div><div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;    <span class="keywordflow">return</span> Identity{};</div><div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;  }</div><div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;</div><div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;<span class="keyword">private</span>:</div><div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;  <span class="keywordtype">int</span> window_size_;</div><div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;  <span class="keywordtype">int</span> offset_;</div><div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;  Identity identity_;</div><div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;  Combiner combiner_;</div><div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;</div><div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;  std::vector&lt;Identity&gt; items{};</div><div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;  <span class="keywordtype">int</span> remaining = 0;</div><div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;};</div><div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;</div><div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;<span class="keyword">namespace </span>internal {</div><div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;</div><div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;<span class="keyword">template</span>&lt;<span class="keyword">typename</span> T&gt;</div><div class="line"><a name="l00124"></a><span class="lineno"><a class="line" href="structgrppi_1_1internal_1_1is__reduce.html">  124</a></span>&#160;<span class="keyword">struct </span><a class="code" href="structgrppi_1_1internal_1_1is__reduce.html">is_reduce</a> : std::false_type {};</div><div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;</div><div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> C, <span class="keyword">typename</span> I&gt;</div><div class="line"><a name="l00127"></a><span class="lineno"><a class="line" href="structgrppi_1_1internal_1_1is__reduce_3_01reduce__t_3_01_c_00_01_i_01_4_01_4.html">  127</a></span>&#160;<span class="keyword">struct </span><a class="code" href="structgrppi_1_1internal_1_1is__reduce.html">is_reduce</a>&lt;<a class="code" href="classgrppi_1_1reduce__t.html">reduce_t</a>&lt;C,I&gt;&gt; :std::true_type {};</div><div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;</div><div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;}</div><div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;</div><div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div><div class="line"><a name="l00132"></a><span class="lineno"><a class="line" href="namespacegrppi.html#abce2309ebb836d19490bfed222b35501">  132</a></span>&#160;constexpr <span class="keywordtype">bool</span> <a class="code" href="namespacegrppi.html#abce2309ebb836d19490bfed222b35501">is_reduce</a> = <a class="code" href="structgrppi_1_1internal_1_1is__reduce.html">internal::is_reduce&lt;std::decay_t&lt;T&gt;</a>&gt;();</div><div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;</div><div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div><div class="line"><a name="l00135"></a><span class="lineno"><a class="line" href="namespacegrppi.html#a4f2ec5252b5fe6ed39a5a3c501b70732">  135</a></span>&#160;<span class="keyword">using</span> <a class="code" href="namespacegrppi.html#a4f2ec5252b5fe6ed39a5a3c501b70732">requires_reduce</a> = std::enable_if_t&lt;is_reduce&lt;T&gt;,<span class="keywordtype">int</span>&gt;;</div><div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;</div><div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;} <span class="comment">// end namespace grppi</span></div><div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;</div><div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;<span class="preprocessor">#endif</span></div><div class="ttc" id="namespacegrppi_html"><div class="ttname"><a href="namespacegrppi.html">grppi</a></div><div class="ttdef"><b>Definition:</b> callable_traits.h:26</div></div>
<div class="ttc" id="classgrppi_1_1reduce__t_html_ab2eaf12acd4842c4b4399fd759b462ed"><div class="ttname"><a href="classgrppi_1_1reduce__t.html#ab2eaf12acd4842c4b4399fd759b462ed">grppi::reduce_t::reduce_t</a></div><div class="ttdeci">reduce_t(int wsize, int offset, Identity id, Combiner &amp;&amp;combine_op)</div><div class="ttdoc">Construct a reduction pattern object. </div><div class="ttdef"><b>Definition:</b> reduce_pattern.h:44</div></div>
<div class="ttc" id="namespacegrppi_html_a4f2ec5252b5fe6ed39a5a3c501b70732"><div class="ttname"><a href="namespacegrppi.html#a4f2ec5252b5fe6ed39a5a3c501b70732">grppi::requires_reduce</a></div><div class="ttdeci">std::enable_if_t&lt; is_reduce&lt; T &gt;, int &gt; requires_reduce</div><div class="ttdef"><b>Definition:</b> reduce_pattern.h:135</div></div>
<div class="ttc" id="namespacegrppi_html_abce2309ebb836d19490bfed222b35501"><div class="ttname"><a href="namespacegrppi.html#abce2309ebb836d19490bfed222b35501">grppi::is_reduce</a></div><div class="ttdeci">constexpr bool is_reduce</div><div class="ttdef"><b>Definition:</b> reduce_pattern.h:132</div></div>
<div class="ttc" id="classgrppi_1_1reduce__t_html_a7a7b53d2b18502ddb41792a696dfdf3e"><div class="ttname"><a href="classgrppi_1_1reduce__t.html#a7a7b53d2b18502ddb41792a696dfdf3e">grppi::reduce_t::combiner</a></div><div class="ttdeci">Combiner combiner() const </div><div class="ttdoc">Get the combiner. </div><div class="ttdef"><b>Definition:</b> reduce_pattern.h:75</div></div>
<div class="ttc" id="structgrppi_1_1internal_1_1is__reduce_html"><div class="ttname"><a href="structgrppi_1_1internal_1_1is__reduce.html">grppi::internal::is_reduce</a></div><div class="ttdef"><b>Definition:</b> reduce_pattern.h:124</div></div>
<div class="ttc" id="classgrppi_1_1reduce__t_html_a14fd59017bf9aae3e37eabd38c75f849"><div class="ttname"><a href="classgrppi_1_1reduce__t.html#a14fd59017bf9aae3e37eabd38c75f849">grppi::reduce_t::reduce_window</a></div><div class="ttdeci">auto reduce_window(const E &amp;e)</div><div class="ttdoc">Reduce values from a window. </div><div class="ttdef"><b>Definition:</b> reduce_pattern.h:94</div></div>
<div class="ttc" id="classgrppi_1_1reduce__t_html_a4966590f756cce91306ae117c6cb4d02"><div class="ttname"><a href="classgrppi_1_1reduce__t.html#a4966590f756cce91306ae117c6cb4d02">grppi::reduce_t::window_size</a></div><div class="ttdeci">int window_size() const </div><div class="ttdoc">Get the window size. </div><div class="ttdef"><b>Definition:</b> reduce_pattern.h:81</div></div>
<div class="ttc" id="classgrppi_1_1reduce__t_html"><div class="ttname"><a href="classgrppi_1_1reduce__t.html">grppi::reduce_t</a></div><div class="ttdoc">Representation of reduce pattern. Represents a reduction that can be used as a stage on a pipeline...</div><div class="ttdef"><b>Definition:</b> reduce_pattern.h:34</div></div>
<div class="ttc" id="classgrppi_1_1reduce__t_html_add1893b889d024147efaba42422cedd1"><div class="ttname"><a href="classgrppi_1_1reduce__t.html#add1893b889d024147efaba42422cedd1">grppi::reduce_t::offset</a></div><div class="ttdeci">int offset() const </div><div class="ttdoc">Get the offset. </div><div class="ttdef"><b>Definition:</b> reduce_pattern.h:87</div></div>
<div class="ttc" id="classgrppi_1_1reduce__t_html_a1c79c7ee533b17d782881b2374216b9b"><div class="ttname"><a href="classgrppi_1_1reduce__t.html#a1c79c7ee533b17d782881b2374216b9b">grppi::reduce_t::reduction_needed</a></div><div class="ttdeci">bool reduction_needed() const </div><div class="ttdoc">Check if a reduction can be performed. </div><div class="ttdef"><b>Definition:</b> reduce_pattern.h:67</div></div>
<div class="ttc" id="classgrppi_1_1reduce__t_html_a7319e39544c636e08643bc7f572def58"><div class="ttname"><a href="classgrppi_1_1reduce__t.html#a7319e39544c636e08643bc7f572def58">grppi::reduce_t::add_item</a></div><div class="ttdeci">void add_item(Identity &amp;&amp;item)</div><div class="ttdoc">Add an item to the reduction buffer. If there are remaining items before reaching the next window sta...</div><div class="ttdef"><b>Definition:</b> reduce_pattern.h:55</div></div>
<div class="ttc" id="classgrppi_1_1reduce__t_html_a2629935ab39526c99432353e68172f62"><div class="ttname"><a href="classgrppi_1_1reduce__t.html#a2629935ab39526c99432353e68172f62">grppi::reduce_t::operator()</a></div><div class="ttdeci">auto operator()(T &amp;&amp;item)</div><div class="ttdef"><b>Definition:</b> reduce_pattern.h:107</div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.11
</small></address>
</body>
</html>
